<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var obj = {
            mame: '张三',
            sex: 'male'
        }
        // 对象字面量
        obj.mame = '李四'
        // 系统自带构造函数
        var obj = new Object()
        obj.name = '张三'
        obj.sex = '男士'

        // 自定义构造函数
        function Teacher(opt) {
            this.name = opt.name;
            this.sex = opt.sex;
            this.weight = opt.weight;
            this.course = opt.course;
            this.smoke = function () {
                this.weight--;
                console.log(this.weight);

            }

            this.eat = function () {
                this.weight++;
                console.log(this.weight);

            }

        }
        // t1对象
        var t1 = new Teacher({
            name: "张三",
            sex: "男",
            weight: 145,
            course: "JavaScript"
        })

        // t1对象
        var t2 = new Teacher({
            name: "李四",
            sex: "女",
            weight: 90,
            course: "HTML"
        })
        t1.smoke()
        t2.eat()
        console.log(t1, t2);

    </script>
    <!-- 作业1 -->
    <!-- 写一个构造函数，接收数字类型的参数，
参数数量不定，完成参数相加和相乘的功能 -->
    <script>
        function Multiply() {
            var args = arguments;
            this.mul = function () {
                var num = 1;
                for (let index = 0; index < args.length; index++) {
                    const element = args[index];
                    num *= args[index];


                }
                return num;
            }

        }
        var multiply = new Multiply(1, 2, 3, 4, 5, 6, 7)
        console.log(multiply.mul());


    </script>
    <!-- 
        写一个构造车的函数，可设置车的品牌，颜色，排量
再写一个构造消费者的函数，设置用户的名字，年龄
，收入，通过选择的方法实例化该用户喜欢的车，
再设置车的属性。
 -->

    <script>
        function Car(opt) {
            this.brand = opt.brand;
            this.color = opt.color;
            this.volume = opt.volume;
        }
        function Consumer(opt) {
            this.name = opt.name;
            this.age = opt.age;
            this.income = opt.income;
            this.car = opt.car;
        }
        var binli = new Car({
            brand: '宾利',
            color: '白色',
            volume: '2.0L'
        });
        var c1 = new Consumer({
            name: 'Gzl',
            age: 10,
            income: 1500,
            car: binli
        });

        console.log(c1);
    </script>
</body>

</html>